package com.example;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.ArrayAdapter;
import android.widget.Toast;

public class ListMessageHandler extends Handler {
	private ArrayAdapter<CharSequence> m_adapterForSpinner;
	private Context context;

	public ListMessageHandler(Context context,
			ArrayAdapter<CharSequence> m_adapterForSpinner) {
		this.m_adapterForSpinner = m_adapterForSpinner;
		this.context = context;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void handleMessage(Message msg) {
		if (msg.obj instanceof HashMap) {
			HashMap<String, String> list = (HashMap<String, String>) msg.obj;
			for (Map.Entry<String, String> entry : list.entrySet()) {
				m_adapterForSpinner.add(entry.getKey());
			}
		} else if (msg.obj instanceof String) {
			String message = (String) msg.obj;
			Toast.makeText(context, message, Toast.LENGTH_LONG).show();
		} else
			Toast.makeText(context,
					"An Error Occured!  Please try again later.",
					Toast.LENGTH_LONG).show();
		

	}
}
